package com.liang.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class HashMaoDemo2 {
    public static void main(String[] args) {
        Map<String, Integer> arr = new HashMap<>();

        arr.put("小米手机", 3999);
        arr.put("华为手机",6999);
        arr.put("苹果手机", 8999);
        arr.put("三星手机", 5999);

        Set<String> strings = arr.keySet();

        for (String string : strings) {
            Integer integer = arr.get(string);
            System.out.println(string+","+integer);

        }

        Scanner sc = new Scanner(System.in);

        while (true) {
            System.out.println("请输入您要查询的手机：");
            String s = sc.nextLine();

            if (arr.containsKey(s)) {
                System.out.println("价格为："+arr.get(s));
                break;
            }else{
                System.out.println("您输入的手机不存在，请重新输入！");
            }
        }
    }
}
